module.exports = function (app, mongoose) {
  app.post("/create", function (req, res) {
    console.log(req.body)
    let data = req.body
    data.ip = req.ip.split(":")[3]
    var Patient = mongoose.model("Patient");
    // 写入数据库B
    var patient = new Patient(data);
    Patient.find({
        name: data.name,
        sex: data.sex,
        phone: data.phone,
      },
      function (err, docs) {
        if (err) {
          console.log("err:", err);
          res.json({
            state: 0,
            msg: "数据库错误"
          });
          return
        } else {
          if (docs == "") {
            patient.save(function (err) {
              // 执行保存，并查看返回情况
              if (err) {
                console.log(err);
              } else {
                res.json({
                  status: 0,
                  msg: "录入成功"
                });
                return
              }
            });
          } else {
            res.json({
              status: 1,
              msg: "这个患者存在"
            });
            return
          }
        }
      })
  });
}
